<?php
#Script that updates each artists friends (available in the (condor) database), that is missing in the dataset
#The link dataset is marked by the actual timestamp

include 'myspacerawler.php';


$crawler = new MySpaceCrawler('output_neu1.txt','myspacedec18','localhost','root','root');
//$crawler->actualDate = '2010-01-03 19:58:41'; // set Timestamp here, if you don't want the actual time and date

$crawler->print_out("Beginn Artists Database update: ". $crawler->actualDate); $artists = $crawler->getArtistsFromCondorDataset(); 

#Track the  actual charts position and save it in 'charts'
$crawler->print_out("\nChart update into charts: ") ;
$charts = $crawler->getArtistsFromUnsignedCharts(1,150);
$crawler->print_out("\nDone") ;
mysql_query("CREATE TABLE IF NOT EXISTS `charts` (`date` DATE, `pos` SMALLINT UNSIGNED, `artist` INT UNSIGNED, PRIMARY KEY(`date`,`pos`), INDEX(`date`)) TYPE = MyISAM ;");
echo mysql_error();
foreach($charts as $friendID){
	$crawler->writeUnsignedArtistsCharts($friendID,++$pos);
}

foreach($artists as $a){
	$i = 0;
	$n = 1;
	$crawler->print_out("\n -------------------------------------------------- \n") ;
	$crawler->print_out("Artist : ". print_r($a,true) . "\n") ;
	$crawler->print_out("Friends on Myspace: "); $newFriends = $crawler->getAllFriendIDs($a['friendID'],1); $crawler->print_out(count($newFriends) . "\n");
	$crawler->print_out("Friends in Database: "); $oldFriends = $crawler->getFriendListFromCondor($a['friendID']);$crawler->print_out(count($oldFriends) . "\n");
	$crawler->print_out("Compare entries: "); 
	foreach($newFriends as $newFriend){
		if(!in_array($newFriend, $oldFriends)){
			unset($profile);
			$profile = $crawler->getShortBasicProfileInfo($newFriend);
			if($profile['sourceType'] != 'band'){
				$i++;
				$crawler->insertProfileInCondor($profile,$a['datasetID']);
				$noneBandFriends[] = $profile['friendID'];
			}
			$crawler->print_out(".");
			if($n % 50 == 0) echo $n . "\n		 ";$n++;
		}
		
	}
	$crawler->print_out("\n");
	$crawler->print_out("New (none band) Friends: ".  $i);
	if($i > 0) $crawler->insertFriendLinksInCondor($a['friendID'],$noneBandFriends,$a['datasetID']);

	unset($noneBandFriends);
	unset($newFriends);
	unset($oldFriends);
	unset($profile);
}

$crawler->__destruct();
unset($crawler);


?>